<?php
class Bus_model extends Model {

    function Bus_model()
    {
        // Call the Model constructor
        parent::Model();
    }
	
	function get_all_buses()
	{
		$query = $this->db->get('buses');
		
		return $query->result_array();
	}
	
    function add_bus()
    {

    }
	
	function get_tour_buses($id)
	{
		$query = $this->db->where('tour_id', $id);
		$query = $this->db->order_by('bus_number');
		$query = $this->db->get('tour_to_bus');
		
		return $query->result_array();
	}
	
	function clear_tour_buses($tour_id)
	{
		$this->db->where(array('tour_id' => $tour_id));		
		$this->db->delete('tour_to_bus');
		
		$this->db->where(array('tour_id' => $tour_id));		
		$this->db->delete('itineraries');
	}
	
	function update_tour_buses($tour_id, $bus_data)
	{
		//$this->db->where(array('tour_id' => $tour_id, 'bus_number' => $bus_data['bus_number']));		
		//$this->db->delete('tour_to_bus');
		
		$data = array(
	               	'tour_id' => $tour_id,
					'bus_id' => $bus_data['bus_type'],
					'bus_number' => $bus_data['bus_number']
		            );
		
		if (!isset($bus_data['default_itinerary']))
		{
			$data['default_itinerary'] = 0;
		}
		
		$this->db->insert('tour_to_bus', $data);
		
		
	}
	

}
?>